﻿using Microsoft.Win32;
using SimpleConnection_UDP_WIN.data;
using System;

namespace SimpleConnection_UDP_WIN.utils
{
    internal class RegistryUtils
    {
        public static bool setString(string key,string value)
        {
            try
            {
                // 写入注册表项的值
                Registry.SetValue(Constant.registry_root_path, key, value);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
         public static string getString(string key,string default_value)
        {
            try
            {
                // 打开注册表项
                if (Registry.GetValue(Constant.registry_root_path, key, default_value) is string value)
                {
                    return value;
                }
                else
                {
                    return default_value;
                }
            }
            catch (Exception)
            {
                return default_value;
            }
        }


        public static bool setInt(string key, int value)
        {
            try
            {
                // 写入注册表项的值
                Registry.SetValue(Constant.registry_root_path, key, value);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static int getInt(string key, int default_value)
        {
            try
            {
                // 打开注册表项
                int value = (int)Registry.GetValue(Constant.registry_root_path, key, default_value);
               
                return value;
          

            }
            catch (Exception)
            {
                return default_value;
            }
        }

    








    }
}
